package flc.ast.adapter;

import android.graphics.Color;
import android.view.View;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.MyWifiBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class WifiAdapter extends StkProviderMultiAdapter<MyWifiBean> {

    public WifiAdapter() {
        addItemProvider(new StkSingleSpanProvider(30));
        addItemProvider(new WifiProvider());
    }

    private class WifiProvider extends BaseItemProvider<MyWifiBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_wifi;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyWifiBean bean) {
            if (baseViewHolder.getBindingAdapterPosition() == 0) {
                baseViewHolder.getView(R.id.line).setVisibility(View.GONE);
            } else {
                baseViewHolder.getView(R.id.line).setVisibility(View.VISIBLE);
            }
            baseViewHolder.setText(R.id.tvWifiItemName, bean.getName());
            if (bean.isOpened()) {
                baseViewHolder.setImageResource(R.id.ivWifiItemImg, R.drawable.wifi);
            } else {
                baseViewHolder.setImageResource(R.id.ivWifiItemImg, R.drawable.wifi1);
            }
            if (bean.isConnect()) {
                baseViewHolder.setText(R.id.tvWifiItemConnect, getContext().getString(R.string.connected));
                baseViewHolder.setTextColor(R.id.tvWifiItemConnect, Color.parseColor("#FFFFFF"));
                baseViewHolder.setBackgroundResource(R.id.tvWifiItemConnect, R.drawable.connect_bg);
            } else {
                baseViewHolder.setText(R.id.tvWifiItemConnect, getContext().getString(R.string.connect));
                baseViewHolder.setTextColor(R.id.tvWifiItemConnect, Color.parseColor("#009933"));
                baseViewHolder.setBackgroundColor(R.id.tvWifiItemConnect, Color.parseColor("#E2F8E9"));
            }
        }
    }
}
